package com.wuxiaofan.api;

import com.wuxiaofan.entity.Dict;
import com.wuxiaofan.service.DictService;
import com.wuxiaofan.vo.ReturnResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/dict")
public class DictApi {
    @Resource
    private DictService dictService;


    /**
     * 导出数据
     * @param response
     * @throws Exception
     */
    @GetMapping("exportData")
    public void exportData(HttpServletResponse response) throws Exception {
        dictService.exportData(response);
    }

    @PostMapping("importData")
    public ReturnResult importData(MultipartFile file) throws Exception {
        dictService.importData(file.getInputStream());
        return ReturnResult.success("上传成功");
    }

    /**
     * 导入数据
     * @param parentId
     * @return
     */

    @GetMapping("findByParentId/{parentId}")
    public ReturnResult findByParentId(@PathVariable("parentId") Long parentId){
        List<Dict> dictList = dictService.findByParentId(parentId);
        return ReturnResult.success("",dictList);
    }


}
